﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Audio;

public class GameCtrl : MonoBehaviour
{

    public int isRun = 1;
    public Button pauseBTN;
    public Slider audioBar;
    public string[] texts = { "继续", "暂停" };
    public PlayerControl pc;
    public Gun fireCtrl;
    public AudioMixer masterMixer;

    // Start is called before the first frame update
    void Start()
    {
        pc = GameObject.Find("Hero").GetComponent<PlayerControl>();
        fireCtrl = GameObject.Find("Gun").GetComponent<Gun>();
        pauseBTN.onClick.AddListener(setGame);
        audioBar.onValueChanged.AddListener(setVolume);
    }

    void setGame()
    {
        isRun = isRun == 1 ? 0 : 1;
        pauseBTN.transform.Find("Text").GetComponent<Text>().text = texts[isRun];
        Time.timeScale = isRun;

        bool isRun_ = isRun == 1 ? true : false;
        pc.enabled = isRun_;
        fireCtrl.enabled = isRun_;
    } 

    void setVolume(float value)
    {
        masterMixer.SetFloat("Vol", value);
    }
}
